package com.Servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.Jdbc;

/**
 * Servlet implementation class user_management_add
 */
@WebServlet("/user_management_add")
public class user_management_add extends HttpServlet {
	private static final long serialVersionusername = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public user_management_add() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String username = request.getParameter("username");
    String truename = request.getParameter("truename");
    String upsw = request.getParameter("pass");
    String urole = request.getParameter("userrole");
    String regist1="insert into user(username,truename,password,role)values('"+username+"','"+truename+"','"+upsw+"','"+urole+"') ";
	String regist2 = "insert into authority(username,truename,role,remarks)values('"+username+"','"+truename+"','"+urole+"','')";
	Jdbc j1 = null;
	Jdbc j2 = null;
	
	try {
		j1= new Jdbc(regist1);
		j2= new Jdbc(regist2);
		;
	} catch (ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	request.getRequestDispatcher("showsuccess.jsp").forward(request, response);
	}
}
